home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 21
/
CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso
/
CUCD
/
Programming
/
Python-1.4
/
Source
/
Amiga
/
Python_netlib
/
stat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-13
|
2KB
|
107 lines
RCS_ID_C="$Id: stat.c,v 4.2 1994/09/29 23:09:02 jraja Exp $";
/*
* stat.c - stat() for the netlib
*
* Copyright © 1994 AmiTCP/IP Group,
* Network Solutions Development Inc.
* All rights reserved.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
/* DOS 3.0 and MuFS extensions to file info block */
#include "fibex.h"
#include "netlib.h"
#include <proto/dos.h>
#include <proto/utility.h>
int stat(const char *name, struct stat *st)
{
short found;
register int rc = -1;
BPTR lock;
if (st == NULL || ((1 & (long)st) == 1)) {
errno = EFAULT;
return -1;
}
lock = Lock((STRPTR)name, SHARED_LOCK);
if (found = lock != NULL) {
if (Examine(lock, __dostat_fib)) {
__dostat(__dostat_fib, st);
st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
rc = 0;
} else {
errno = EIO;
}
} else {
UBYTE errcode = IoErr();
if (errcode == ERROR_OBJECT_IN_USE) {
rc = lstat(name, st);
} else {
set_errno(errcode);
}
}
if (lock)
UnLock(lock);
return rc;
}
int lstat(const char *name, struct stat *st)
{
/* Cannot lock - do examine via Examine()/ExNext() */
int rc = -1;
char *cname;
if (st == NULL || ((1 & (long)st) == 1)) {
errno = EFAULT;
return -1;
}
cname = malloc(strlen(name) + 1);
if (cname) {
BPTR lock;
char *pp = PathPart(strcpy(cname, name));
*pp = '\0';
if (lock = Lock(cname, SHARED_LOCK)) {
pp = FilePart((STRPTR)name);
if (Examine(lock, __dostat_fib)) {
while (ExNext(lock, __dostat_fib)) {
if (Stricmp(pp, __dostat_fib->fib_FileName) == 0) {
__dostat(__dostat_fib, st);
st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
rc = 0;
break;
}
}
}
if (rc != 0)
errno = ENOENT;
} else {
set_errno(IoErr());
}
if(lock) UnLock(lock); /* I.J. 13-Apr-96 */
free(cname);
} else {
errno = ENOMEM;
}
return rc;
}